<!--
 * @Author: yehongbo 1394168736@qq.com
 * @Date: 2024-01-17 09:46:38
 * @LastEditors: yehongbo 1394168736@qq.com
 * @LastEditTime: 2024-01-17 14:47:51
 * @FilePath: \giteeDownload\vue3ant\src\views\zixulie.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!--
 * 输入：s1 = "abc", s2 = "def"

输出：0

解释：两个字符串没有公共子序列，返回 0 。

输入：s1 = "abc", s2 = "abc"

输出：3

解释：最长公共子序列是 "abc" ，它的长度为 3 。

提示：


s1 和 s2 仅由小写英文字符组成。
-->
<template>
  <div id="div1"></div>
</template>

<script setup>
const longestCommonSubsequence = (s1, s2) => {
  const n = s1.length, m = s2.length;
  const cs1 = s1.split(''), cs2 = s2.split('');
  const f = Array.from({ length: n + 1 }, () => Array(m + 1).fill(0));
  for (let i = 1; i <= n; i++) {
    for (let j = 1; j <= m; j++) {
      if (cs1[i - 1] == cs2[j - 1]) f[i][j] = f[i - 1][j - 1] + 1;
      else f[i][j] = Math.max(f[i - 1][j], f[i][j - 1]);
    }
  }
  return f[n][m];
};
console.log(longestCommonSubsequence('fg', 'abcd'))
</script>

<style>
#mountNode {
  width: 100%;
  height: 500px;
}
</style>

